<template>
	<el-button type="primary" @click="add()">
		添加
	</el-button>
	<el-table :data="permissionData">
		<el-table-column prop="name" label="权限名称">
			
		</el-table-column>
		<el-table-column label="操作">
			<template #default="scope">
				
				<el-button type="warning" @click="update(scope.row)">
					修改
				</el-button>
				<el-button color="red" @click="del(scope.row.id)">
					删除
				</el-button>
			</template>
		</el-table-column>
	</el-table>
	<el-dialog
	    v-model="dialogVisible"
	    title="添加权限"
	    width="30%"
	  >
	  <el-input placeholder="请输入权限名" v-model="name"></el-input>
	    <template #footer>
	      <span class="dialog-footer">
	        <el-button @click="dialogVisible = false">Cancel</el-button>
	        <el-button type="primary" @click="addSubmit"
	          >Confirm</el-button
	        >
	      </span>
	    </template>
	  </el-dialog>
	  <el-dialog
	      v-model="dialogVisible_update"
	      title="修改权限"
	      width="30%"
	    >
	    <el-input placeholder="请输入权限名" v-model="name"></el-input>
	      <template #footer>
	        <span class="dialog-footer">
	          <el-button @click="dialogVisible_update = false">Cancel</el-button>
	          <el-button type="primary" @click="updateSubmit"
	            >Confirm</el-button
	          >
	        </span>
	      </template>
	    </el-dialog>
	  <el-dialog
	      v-model="dialogVisible_del"
	      title="删除权限"
	      width="30%"
	    >
	    你确定要删除id为{{id}}这个权限吗？
	      <template #footer>
	        <span class="dialog-footer">
	          <el-button @click="dialogVisible_del = false">Cancel</el-button>
	          <el-button type="primary" @click="delSubmit"
	            >Confirm</el-button
	          >
	        </span>
	      </template>
	    </el-dialog>
</template>

<script setup>
	import {ref} from 'vue'
	import http from './request.js'
	const permissionData = ref([])
	const dialogVisible = ref(false)
	const dialogVisible_del = ref(false)
	const dialogVisible_update = ref(false)
	const name = ref('')
	function query(){
		http.get('/permission/queryAll').then(res=>{
			permissionData.value = res.data
		})
	}
	query()
	function add(){
		dialogVisible.value = true
		name.value = ''
	}
	function addSubmit(){
		http.post('/permission/save',{name:name.value}).then(res=>{
			dialogVisible.value = false
			query()
		})
	}
	const id = ref(undefined)
	function update(e){
		dialogVisible_update.value = true
		name.value = e.name
		id.value = e.id
	}
	function updateSubmit(){
		http.post('/permission/update',{name:name.value,id:id.value}).then(res=>{
			dialogVisible_update.value = false
			query()
		})
	}
	function del(e){
		dialogVisible_del.value = true
		id.value = e
	}
	function delSubmit(){
		http.get('/permission/del?id='+id.value).then(res=>{
			dialogVisible_del.value = false
			query()
		})
	}
</script>

<style>
</style>